<?php
namespace app\admin\controller;

use app\AdminBaseController;
use app\admin\model\Nav as NavModel;


class Nav extends AdminBaseController
{
    // 菜单列表
    public function index()
    {
        $navModel = new NavModel();
        $res=$navModel->getList('nav',$this->page,$this->size,["nid"=>0,"is_del"=>0],'sort asc');
        $assignData=[
            'data'     =>$navModel->getNavChild($res["data"]->toArray()),
            'count'    =>$res['count'],
            "query"    =>$this->query,
            'pageTotal'=>$this->size,
            'curr'     =>$this->page,
        ];
        return view("index",$assignData);
    }
    /**
     * 添加后台用户
     */
    public function add()
    {
        if($this->request->post()){
            $navModel = new NavModel();
            $data=$navModel->validate();
            $data["createdate"]=time();
            $this->dbSave("nav",$data);
        }
        return view('add');
    }
    /**
     * 修改
     */
    public function update(){
        $navModel = new NavModel();
        $admin = $navModel->where('id',$this->data['id'])->find();
        if($this->request->post()){
            $data=$navModel->validate();
            $this->dbUpdate("nav",$data,["id"=>$data["id"]]);
        }
        return view('update',["admin"=>$admin]);
    }
    /**
     * 更改状态 启用禁用
     */
    public function status(){
        $navModel = new NavModel();
        $data=$navModel->validate();
        $this->dbUpdate("nav",$data,["id"=>$data["id"]]);
    }
    /**
     * 批量删除 单个删除
     */
    public function delete(){
        $navModel = new NavModel();
        $data=$navModel->validate();
        $where[] = ['id', 'in', explode(',', $data['id'])];
        $this->dbDelete("nav", $where);
    }
}
